﻿using System;

using FlickrNet;
using FlickrApi = FlickrNet.Flickr;


namespace Yorrick.FlickrMetadataSynchr.Flickr
{
    /// <summary>
    /// Class that asynchronously fetches photo information from Flickr.
    /// </summary>
    internal sealed class AsyncPhotoInfoFetcher: AsyncFlickrWorker<Photo, PhotoInfo>
    {
        #region Constructor
        /// <summary>
        /// Constructs a new instance.
        /// </summary>
        /// <param name="flickrApi">The Flickr API object to use.</param>
        public AsyncPhotoInfoFetcher(FlickrApi flickrApi): base(flickrApi, "FetchFlickrPhotoInfo")
        {
        }
        #endregion

        #region Protected methods
        /// <summary>
        /// Returns the <see cref="PhotoInfo"/> for when an error occurred. Always returns <c>null</c> because in that
        /// case there is no photo info.
        /// </summary>
        /// <param name="metadata">The metadata for the photo that could not be fetched.</param>
        /// <returns>Always <c>null</c>.</returns>
        protected override PhotoInfo GetMetadataInCaseOfError(Photo metadata)
        {
            return null;
        }

        /// <summary>
        /// Gets the <see cref="PhotoInfo"/> for the specified picture.
        /// </summary>
        /// <param name="metadata">The <see cref="Photo"/> object with the identifying information for the picture.</param>
        /// <returns>The <see cref="PhotoInfo"/> for the specified picture.</returns>
        protected override PhotoInfo ProcessItem(Photo metadata)
        {
            PhotoInfo photoInfo = FlickrApi.PhotosGetInfo(metadata.PhotoId, metadata.Secret);

            return photoInfo;
        }
        #endregion
    }
}
